<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>修改密码·思通投研·让数据驱动投资价值!</title>
	<link href="${pageContext.request.contextPath }/img/webLogoIcon.png" rel="shortcut icon">
	<link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/font-awesome.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/style.css" rel="stylesheet">
	<!-- Toastr style -->
	<link href="${pageContext.request.contextPath }/css/plugins/toastr/toastr.min.css" rel="stylesheet">

	<style type="text/css">
	.form-group{
		margin-bottom: 18px;
	}
	.phonetip{
		color: red;
		display: inline;
		float: right;
	}
	.tip{
   		margin-left: 3px;
	}
	</style>
</head>

<body id="wrapper">
	<nav class="navbar-default navbar-static-side" role="navigation">
		<%request.setAttribute("LEFT", "updatePassword");%>
		<%@include file="datasource-left.jsp"%>
    </nav>
    <div id="page-wrapper" class="gray-bg">
	    <div class="row border-bottom">
	     	<jsp:include page="head.jsp" flush="true" /> 
	    </div>
	    <div class="row wrapper border-bottom white-bg page-heading">
	        <div class="col-lg-9">
	            <h2>修改密码</h2>
	            <ol class="breadcrumb">
	                	<li class="nav-main1"><a>主页</a>
	                	</li>
	                	<li class="active" >
	                		<a id="navigation1" href="#" >修改密码</a>
	                	</li>
                	</ol>
	        </div>
	    </div>
	    <!-- <div class="middle-box text-center loginscreen   animated fadeInDown">
	        <div>
	            <div>
	
	                <h1 class="logo-name"> </h1>
	
	            </div>
	            
	            <form class="m-t" role="form" action="javascript:void(0)" >
	           		<div class="form-group">
	                   
	                </div>
	                <div class="form-group">
	                	<font class="tip pull-left">请输入原密码</font>
	                     <input type="password" name="password" id="password" class="form-control" placeholder="请输入原密码" required="">
	                	<font class="phonetip" id="phonetip" style="display:none;">请输入正确密码</font>
	                </div>
	                <div class="form-group">
	                	<font class="tip pull-left">请输入新密码</font>
	                    <input type="password" name="name" id="repassword" class="form-control" placeholder="请输入新密码" required="">
	                	<font class="phonetip" id="repasswordtip" style="display:none;">请输入正确密码</font>
	                </div>
	                <div class="form-group">
	                	<font class="tip pull-left">请再次输入新密码</font>
	                    <input type="password" name="password" id="repassword1"  class="form-control" placeholder="请再次输入新密码" required="">
	                	<font class="phonetip" id="repasswordtip1" style="display:none;">请输入正确密码</font>
	                </div>
	                
	                <button style="margin-top: 55px;" id="sumit" class="btn btn-primary block full-width m-b" >确认修改</button>
	            </form>
	        </div>
	        
	    </div> -->
	    <div class="passwordBox animated fadeInDown">
	    	<div class="row">
	    		<div class="col-md-12">
                <div class="ibox-content">

                    <h2 class="font-bold">修改密码</h2>

                    <p>
                       	 &nbsp;&nbsp;&nbsp;请输入原密码和新密码，密码格式为:6到12位数字或字母组成，不能包含特殊字符。
                    </p>

                    <div class="row">

                        <div class="col-lg-12">
                            <form class="m-t" role="form" action="javascript:void(0)">
                                <div class="form-group">
                                    <input type="password" name="password" id="password" class="form-control" placeholder="请输入原密码" required="">
	                				<span class="phonetip" id="phonetip" style="display:none;">请输入正确密码</span>
                                </div>
								 <div class="form-group">
				                    <input type="password" name="name" id="repassword" class="form-control" placeholder="请输入新密码" required="">
				                	<span class="phonetip" id="repasswordtip" style="display:none;">请输入正确密码</span>
				                </div>
				                <div class="form-group">
				                    <input type="password" name="password" id="repassword1"  class="form-control" placeholder="请再次输入新密码" required="">
				                	<span class="phonetip" id="repasswordtip1" style="display:none;">请输入正确密码</span>
				                </div>
                                <button type="submit" id="sumit"  class="btn btn-primary block full-width m-b">确认修改</button>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
	    	</div>
	    </div>
	    
	    <jsp:include page="footer.jsp" flush="true" />
    </div>

    <!-- Mainly scripts -->
	<script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
	<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath }/js/plugins/metisMenu/jquery.metisMenu.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
	<!-- Custom and plugin javascript -->
	<script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/plugins/pace/pace.min.js"></script>
	<!-- Toastr script -->
    <script src="${pageContext.request.contextPath }/js/plugins/toastr/toastr.min.js"></script>
<script type="text/javascript">
	$(function(){
		
	});
	$('#sumit').click(function(){
		var password = $("#password").val();
		var repassword = $("#repassword").val();
		var repassword1 = $("#repassword1").val();
		var institution_name = $("#institution_name").val();
		if(password == "" || password == null || !telRuleCheck2(password)  || repassword == "" || repassword == null || !telRuleCheck2(repassword1) || repassword1 == "" || repassword1 == null || !telRuleCheck2(repassword1) ){
			return;
		}else{
			if(repassword != repassword1){
        		$("#repasswordtip").attr("style","color: red;display: inline;float: right;");
                $("#repasswordtip").html("两次输入新密码不一致请确认");
                $("#sumit").attr("disabled","true");
                return;
        	}
			var data= {password:password,repassword:repassword,user_id:$("#user_id").attr("data-id")};
			regist(data);
		}
	});
	function regist(data){
		 $.ajax({
	        type:"POST",
	        url:"${pageContext.request.contextPath}/repassword",
	        data:data,
			dataType:'json',
			success:function(result){
	  			toastr.success('修改成功！请重新登陆');
	  			sessionStorage.clear()
	  			setTimeout(function () {
  					window.location.href = "${pageContext.request.contextPath}/exit";
   				}, 4000);
			},
		}); 
	}
	//验证原密码
    $("#password").blur("blur",function(){
        var password = $("#password").val();
        /* if(telphone == ""){
        } */
        if(!(!password)){
            if(telRuleCheck2(password)){
            	
            	$.ajax({
        	        type:"POST",
        	        url:"${pageContext.request.contextPath}/checkPassword",
        	        data : {
        	        	password:password,
        	        	user_id:$("#user_id").attr("data-id")
					},
        			success:function(result){
        				if(result.status == 200){
        					$("#phonetip").attr("style","display:none;");
        					$("#sumit").attr("disabled",false);
        				}else{
        					$("#phonetip").attr("style","color: red;display: inline;float: right;");
        					$("#phonetip").html("密码错误，请输入正确密码");
        					$("#sumit").attr("disabled","true");
        				}
        			},
        		});
            }
            else
            {
                $("#phonetip").attr("style","color: red;display: inline;float: right;");
                $("#phonetip").html("密码格式不正确，请输入正确密码");
                $("#sumit").attr("disabled","true");
            };
        };
    });
	
  //验证新密码格式
    $("#repassword").blur("blur",function(){
        var repassword = $("#repassword").val();
        if(!(!repassword)){
            if(!telRuleCheck2(repassword)){
                $("#repasswordtip").attr("style","color: red;display: inline;float: right;");
                $("#repasswordtip").html("密码格式不正确，请输入正确密码");
                $("#sumit").attr("disabled","true");
            }else{
            	$("#repasswordtip").attr("style","display:none;");
            	$("#sumit").attr("disabled",false);
            	
            };
        };
    });
    //验证新密码1格式
    $("#repassword1").blur("blur",function(){
        var repassword1 = $("#repassword1").val();
        if(!(!repassword1)){
            if(!telRuleCheck2(repassword1)){
                $("#repasswordtip1").attr("style","color: red;display: inline;float: right;");
                $("#repasswordtip1").html("密码格式不正确，请输入正确密码");
                $("#sumit").attr("disabled","true");
            }else{
            	$("#repasswordtip1").attr("style","display:none;");
            	$("#sumit").attr("disabled",false);
            	if($("#repassword").val() != repassword1){
            		$("#repasswordtip1").attr("style","color: red;display: inline;float: right;");
                    $("#repasswordtip1").html("两次输入新密码不一致请确认");
                    $("#sumit").attr("disabled","true");
            	}else{
            		$("#repasswordtip1").attr("style","display:none;");
                	$("#sumit").attr("disabled",false);
            	}
            }
        };
    });
    telRuleCheck2 = function (string) {
    	var pattern =  /^[a-zA-Z0-9]{6,12}$/;
    	if (pattern.test(string)) {
    		return true;
    	}
    	return false;
    };
	//跑马灯方法 
// 	 function init(){
// 		    //获取标题
// 		    var title=document.title;
// 		    //分割字符串--->字符数组
// 		    var arr=title.split("");
// 		    //删除第一个元素并返回该元素
// 		    var e=arr.shift();
// 		    //把一个对象添加到数组末尾
// 		    arr.push(e);
// 		    //把数组转换成字符串
// 		    var marquee=arr.join("");
// 		    //返回给浏览器
// 		    document.title=marquee;
// 		    //定时一直执行
// 		    window.setTimeout("init()",1000);
// 		}
// 		window.onload=init;
	 
</script>
</body>

</html>
